import datetime
import sys

class RequestLoggerMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        REMOTE_ADDR = request.META.get('REMOTE_ADDR')
        HTTP_USER_AGENT = request.META.get('HTTP_USER_AGENT')
        REQUEST_METHOD = request.META.get('REQUEST_METHOD')
        PATH_INFO = request.META.get('PATH_INFO')
        SERVER_PROTOCOL = request.META.get('SERVER_PROTOCOL')
        NOW = datetime.datetime.now()
        sys.stdout.write(f'''[{NOW}] {REMOTE_ADDR} {SERVER_PROTOCOL}" ''')
        sys.stdout.flush()
        return self.get_response(request)